from selenium import webdriver
import time
browser = webdriver.Chrome()
# browser.get('https://www.baidu.com/')
# print(browser.page_source)
# browser.close()
# 元素交互操作
# browser.get('https://www.taobao.com/')
# input = browser.find_element_by_id('q')
# input.send_keys('iphone')
# time.sleep(1)
# input.clear()
# input.send_keys('小米手机')
# button = browser.find_element_by_class_name('btn-search')
# button.click()
# 执行js
# browser.get('https://www.taobao.com/')
# # browser.execute_script('window.scrollTo(),document.body.scrollHeight')
# # browser.execute_script('alert("To Button")')
# 前进后退
# browser.get('https://www.taobao.com/')
# browser.get('http://817.dopa.com/?dm=%E7%99%BE%E5%BA%A6.com&acc=5D5A62D6-E069-4097-BAAC-2E895820346F&poprequest=1')
# browser.get('https://www.jd.com/?cu=true&utm_source=baidu-pinzhuan&utm_medium=cpc&utm_campaign=t_288551095_baidupinzhuan&utm_term=0f3d30c8dba7459bb52f2eb5eba8ac7d_0_afb78e668693451c824310f7c11bda20')
# browser.back()
# time.sleep(1)
# browser.forward()
# browser.close()
# 选项卡,就是打开一个新的页面
browser.get('https://www.taobao.com/')
browser.execute_script('window.open()')
browser.switch_to_window(browser.window_handles[1])
browser.get('https://www.baidu.com/')
time.sleep(1)
browser.switch_to_window(browser.window_handles[0])
browser.get('https://www.tmall.com/?from=tianmao.com')